﻿using System;
using System.Collections.Generic;
using UnityEngine;

public class HomeVCData
{
    public string name;
    public float birthYear;
    public string xingzuo;
    public string location;
    public string job;
    public string edu;
    public float height;
    public float weight;
    public float income;
}

public class HomeViewController : ViewController
{
    private MBattleSceneController battleSceneController => GetComponentInParent<MBattleSceneController>();
    MBattleController battleScene => battleSceneController .mBattleController;

    HomePanel m_Panel;
    public HomePanel panel => m_Panel;

    HomeVCData m_Data;

    public HomePanel Init(HomeVCData data)
    {
        if (m_Panel == null)
            m_Panel = InitUI();

        GameDebug.LogError($"data != null:{data != null}");

        m_Data = data;
        m_Panel.Init(data);

        return m_Panel;
    }

    protected override void WillLoadView()
    {
        base.WillLoadView();
    }

    protected virtual HomePanel InitUI()
    {
        HomePanel prefab = ResourceManager.Load<HomePanel>(ViewPath.homePanel);
        if (prefab == null)
        {
            GameDebug.LogError("HomePanel prefab null");
            return null;
        }
        m_Panel = GameObject.Instantiate<HomePanel>(prefab, transform);
        m_Panel.SetViewController(this);
        // panel.name = "战斗UI";
        return m_Panel;
    }

    public override void WillHideView()
    {
        base.WillHideView();

        if (m_Panel)
        {
            m_Panel.PlayHideAnim();
        }
    }


    public override void OnViewDelete()
    {
        base.OnViewDelete();

        if (m_Panel)
        {
            Destroy(m_Panel.gameObject);
        }
        m_Panel = null;
    }

    public static HomeVCData GetHomeVCData(MGameUser gameUser)
    {
        HomeVCData homeVcData = new HomeVCData();

        homeVcData.name = gameUser.name;
        homeVcData.birthYear = gameUser.userInfo.birthYear;
        homeVcData.location = "New York";
        homeVcData.xingzuo = "Virgo";
        homeVcData.job = "Jobless";
        homeVcData.edu = DataString.GetEducationString(gameUser.userInfo.eduation);
        homeVcData.height = gameUser.userInfo.height;
        homeVcData.weight = gameUser.userInfo.weight;
        homeVcData.income = gameUser.userInfo.income;
        
        return homeVcData;
    }
}